package com.superteam.zzl.activity;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.superteam.zzl.activity.databinding.ActivitySearchBinding;
import com.superteam.zzl.app.MyApplication;

public class SearchActivity extends BaseActivity implements View.OnClickListener{

    private ActivitySearchBinding searchBinding;
    private EditText et;
    private TextView tv;

    @Override
    public void widgetClick(View v) {

    }

    @Override
    public ViewDataBinding initDataBinding() {
        searchBinding = DataBindingUtil.setContentView(this,R.layout.activity_search);
        et = (EditText) findViewById(R.id.et_search);
        searchBinding.setTvClick(this);
        tv = (TextView)findViewById(R.id.tb).findViewById(R.id.tv_search_1);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = getIntent();
                setResult(444,intent);
                finish();
            }
        });
        et.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            public boolean onEditorAction(TextView v, int actionId,KeyEvent event)  {
                if (actionId== EditorInfo.IME_ACTION_SEND ||
                        (event!=null&&event.getKeyCode()== KeyEvent.KEYCODE_ENTER)) {
                    if(!et.getText().toString().equals("")) {
                        MyApplication.search=et.getText().toString();
                        startActivityForResult(new Intent(SearchActivity.this, SearchResultActivity.class), 444);
                        et.setImeOptions(EditorInfo.IME_ACTION_DONE);
                    }else{
                        Animation shake = AnimationUtils.loadAnimation(SearchActivity.this, R.anim.et_error);
                        et.startAnimation(shake);

                    }
                    return true;
                }
                return false;
            }
        });
        return searchBinding;
    }

    @Override
    public void initParms(Bundle parms) {

    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public void initView(View view) {

    }

    @Override
    public void setListener() {

    }


    @Override
    public void onClick(View v) {
        //Intent intent = getIntent();
        switch (v.getId()){
            case R.id.tv_all://全球搜索
                startActivityForResult(new Intent(this,WorldActivity.class),555);
                break;
        }
    }

    @Override
    public void doBusiness(Context mContext) {

    }

    public void click(View view){
        switch (view.getId()){
            case R.id.tv_search_1://取消
//                setResult(444);
//                finish();
                startActivity(new Intent(this,SearchResultActivity.class));
                break;
        }
    }
}
